<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <script src="/js/utils.js"></script>
    <style type="text/css">
        .layui-table-cell{height:40px;line-height:40px;}
    </style>
</head>
<body>

<blockquote class="layui-elem-quote quoteBox mod_default_box">
    <form class="layui-form">
        <div class="layui-inline">
            <div class="layui-input-inline">
                <input type="text" name="name" placeholder="请输入子模块名称" autocomplete="off" class="layui-input" />
            </div>
            <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="search-stu-submit">
                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
        </div>
    </form>
</blockquote>

<!--数据列表-->
<table class="layui-hide" id="test" lay-filter="stu-table"></table>
<script type="text/html" id="tb">
    <div class="layui-container" style="margin-left:0px;">
        <a class="layui-btn layui-btn-xs add-module" lay-event="add" style="display: none;"><i class="layui-icon layui-icon-addition"></i>新增模块</a>
        <a class="layui-btn layui-btn-xs" lay-event="lunbo"><i class="layui-icon layui-icon-picture"></i>轮播图</a>
    </div>
</script>
<script type="text/html" id="stu-toolbar">
    <a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑模块信息</a>
</script>
<!--<script type="text/html" id="checkboxTpl">-->
<!--    <input type="checkbox" name="status" value="{{d.id}}" title="启用" lay-filter="lockDemo" {{ d.status == 1 ? 'checked' : '' }} />-->
<!--</script>-->
<script src="/js/layui/layui.js"></script>


<script>
    // function getQueryVariable(variable)
    // {
    //     var query = window.location.search.substring(1);
    //     var vars = query.split("&");
    //     for (var i=0;i<vars.length;i++) {
    //         var pair = vars[i].split("=");
    //         if(pair[0] == variable){return pair[1];}
    //     }
    //     return(false);
    // }
    var type= getQueryVariable("type");
    // if(type=='index')
    //     type="首页";
    // else if(type=='jianjie')
    //     type='简介';
    // else if(type=='jiuye')
    //     type='就业';
    // else if(type=='teacher')
    //     type='师资';
    // else if(type=='huanjing')
    //     type='环境';

    layui.use('table', function(){
        var $ = layui.$;
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;

        table.render({
            elem: '#test'
            ,id:'stu-table-id'//重载需要
            ,url:'/module/selectModulePage?type='+type
            ,title:'通知表'
            ,toolbar: '#tb'
            ,cols: [[
                {field: 'id',title: '序号',type:'numbers',width:80,align: 'center'}
                ,{field:'name',align : 'center',width : 180, title: '模块名称'}
                // ,{field:'contentType',width : 140,align : 'center', title: '内容类型'}
                ,{field:'introduce',align : 'center',width : 520, title:'模块介绍'}
                // ,{field:'isShowApp',align : 'center', title:'显示到H5页面',width:160,templet:function (d) {
                //         if (d.isShowApp == 0) {
                //             return "否"
                //         }else {
                //             return "是"
                //         }
                // }}
                // ,{field:'isShowWeb',align : 'center', title:'显示到Web端',width:160,templet:function (d) {
                //         if (d.isShowWeb == 0) {
                //             return "否"
                //         }else {
                //             return "是"
                //         }
                // }}
                // ,{field:'parentName',align : 'center', width : 140,title: '所属分类'}
                // ,{field:'status',align : 'center', title:'是否启用',width:110, templet: '#checkboxTpl', sort: true}
                ,{field:'createDate',align : 'center', width : 200,title: '创建时间'}
                ,{toolbar:"#stu-toolbar",align : 'center',title:"操作",width:200,fixed: 'right'}
            ]]
            ,page: true
            ,page: {
                curr: layui.data("index_page").index
            },
            done: (res, curr, count) => {
                if(type=='teacher')
                    $(".add-module").show();
                layui.data("index_page", {
                    key: 'index',
                    value: curr
                });
            }
        });


        //搜索操作
        form.on('submit(search-stu-submit)',function (data) {
            table.reload('stu-table-id',{
                where:{"name":data.field.name}
                ,page:{
                    curr:1
                }
            });
            return false;
        });


        //监听启用操作
        form.on('checkbox(lockDemo)', function(obj){
            var id = this.value;
            var status = obj.elem.checked;
            var zhuangtai;
            if(status){
                zhuangtai=1;
            }else{
                zhuangtai=0;
            }
            $.ajax({
                url:"/module/upStatus"
                ,type:"get"
                ,data:{id:id,status:zhuangtai}
                ,contentType: 'application/json'
                ,success:function (data) {
                    if(data.code==0){
                        layer.close(layer.index);
                        layer.msg('操作成功');
                    }else if(data.code==1){
                        layer.msg('操作失败');
                    }else{
                        layer.msg('没有权限');
                    }
                }
                ,error:function () {
                    console.log("ajax error");
                }
            });
        });

        table.on('toolbar(stu-table)', function (obj) {
            if (obj.event === 'add') {
                layer.open({
                    type: 2
                    ,title: "添加模块信息"
                    ,area: ['100%', '100%']
                    ,content: (encodeURI("add_module.html?parentName="+type)) //这里content是一个普通的String
                });
            }else if(obj.event=="lunbo"){
                layer.open({
                    type: 2
                    ,title: "页面轮播图"
                    ,area: ['90%', '90%']
                    ,content: (encodeURI("../lunbo/lunboList.html?type="+type)) //这里content是一个普通的String
                });
            }

        });

        table.on('tool(stu-table)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                layer.open({
                    type: 2
                    ,title: "修改模块信息"
                    ,area: ['100%', '100%']
                    ,content: (encodeURI("update_module.html?id=" + data.id)) //这里content是一个普通的String
                });
            }
        });
    });
</script>
<script>
    function previewImgs(obj) {
        var img = new Image();
        img.src = obj.src;
        //var height = img.height + 50; // 原图片大小
        //var width = img.width; //原图片大小
        var imgHtml = "<img src='" + obj.src + "' width='800px' height='500px'/>";
        //弹出层
        layer.open({
            type: 1,
            shade: 0.8,
            offset: 'auto',
            area: [800 + 'px', 550 + 'px'],// area: [width + 'px',height+'px'],  //原图显示
            shadeClose: true,
            scrollbar: false,
            title: "图片预览", //不显示标题
            content: imgHtml, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
            cancel: function () {
                //layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', { time: 5000, icon: 6 });
            }
        });
    }
</script>
</body>
</html>